package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.Tag;
import cn.kgc.springcloud.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: mosin
 * @version: v1.0  2022/8/28
 */
@RestController
@RequestMapping("tags")
public class TagController {

    @Autowired
    private TagService tagService;
    @GetMapping
    public List<Tag> tagList(){
        List<Tag> tags =   tagService.findAll();
        return tags;
    }

    @PostMapping
    public Tag addTag(@RequestBody Tag tag){
        Tag tg =   tagService.addTag(tag);
        return tg;
    }

    @DeleteMapping("{id}")
    public Boolean deleteTag(@PathVariable Integer id){
        Boolean b =   tagService.deleteTagById(id);
        return b;
    }

    @GetMapping("{tagId}")
    public Tag findTagById(@PathVariable Integer tagId){
       Tag tag =   tagService.findOne(tagId);
        return tag;
    }





}
